package com.treasure.service.task.job.wechat;

import org.quartz.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;


@DisallowConcurrentExecution
public class WechatJob implements Job {
    private Logger logger = LoggerFactory.getLogger(this.getClass());
    public WechatJob(){
    }

    @Autowired
    RestTemplate restTemplate;

    @Value("${treasure.rest.service.wechat}")
    private String requestUrl;

    public void execute(JobExecutionContext context)
        throws JobExecutionException {
        JobKey key = context.getJobDetail().getKey();
        long start = System.currentTimeMillis();
        logger.info("更新公众号Access_token Instance " + key);
        MultiValueMap<String, String> requestEntity = new LinkedMultiValueMap<>();
        restTemplate.postForObject(requestUrl+"/updateAccess_token",requestEntity,String.class);
        logger.info("更新公众号Access_token Instance " + key+ ":{}",(System.currentTimeMillis()-start));
    }
}
